import type { Effect, Reducer } from 'umi';
import { message } from 'antd';
export type CurrentState = {
  current?: '';
};

export type NewsType = {
  namespace: 'login';
  state: CurrentState;
  effects: {
    fetchIsLogin: Effect;
  };
  reducers: {
    setLogin: Reducer<CurrentState>;
  };
};
const currentModel = {
  namespace: 'current',
  state: {
    CurrentState: localStorage.getItem('key') || 'home',
  },
  effects: {
    *fetchIsLogin({ payload }, { call, put }) {
      try {
        yield put({
          type: 'setLogin',
          payload: payload,
        });
      } catch (err) {
        message.error('');
      }
    },
  },
  reducers: {
    setLogin(state, { payload }) {
      const { key } = payload;
      return {
        ...state,
        CurrentState: key,
      };
    },
  },
};
export default currentModel;
